package com.ytjj.qmyx.admin.controller.channelProductController;


import com.ytjj.common.api.CommonPage;
import com.ytjj.common.controller.BaseController;
import com.ytjj.qmyx.admin.model.request.FreigRequest;
import com.ytjj.qmyx.admin.model.request.YxAssignFreight;
import com.ytjj.qmyx.admin.model.request.YxAstrictRegion;
import com.ytjj.qmyx.admin.model.request.YxFreightTemplate;
import com.ytjj.qmyx.admin.model.response.goods.FreightTemplateResponse;
import com.ytjj.qmyx.admin.service.channelProductService.FreightTemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ytjj.common.api.CommonResult;






/**
 * 运费模板表
 *
 *
 * @email 
 * 
 */
@RestController
@RequestMapping("/product/freightTemplate")
public class ProductFreightTemplateController extends BaseController {

    @Autowired
    private FreightTemplateService freightTemplateService;


    /**
     * 模板列表
     * @return
     */
    @PostMapping("/page")
    public CommonResult selectFreightTemplatePage(@RequestBody FreigRequest freigRequest) {
        CommonPage commonPage = freightTemplateService.selectFreightTemplatePage(freigRequest);
        return CommonResult.success(commonPage);
    }


    /**
     * 新建模板
     * @param yxFreightTemplate
     * @return
     */
    @PostMapping("/insertFreightTemplate")
    public CommonResult insertFreightTemplate(@RequestBody YxFreightTemplate yxFreightTemplate) {
        return CommonResult.success(freightTemplateService.insertFreightTemplate(yxFreightTemplate));
    }

    /**
     * 模板删除
     * @return
     */
    @GetMapping("/deleteFreightTemplate")
    public CommonResult deleteFreightTemplate(Integer id) {
        return CommonResult.success(freightTemplateService.deleteFreightTemplate(id));
    }

    /**
     * 删除指定运费
     * @return
     */
    @GetMapping("/deleteAssignFreight")
    public CommonResult deleteAssignFreight(Integer id) {
        return CommonResult.success(freightTemplateService.deleteAssignFreight(id));
    }

    /**
     * 删除限制下单区域
     * @return
     */
    @GetMapping("/deleteAstrictRegion")
    public CommonResult deleteAstrictRegion(Integer id) {
        return CommonResult.success(freightTemplateService.deleteAstrictRegion(id));
    }

    /**
     * 修改指定运费
     * @param yxAssignFreight
     * @return
     */
    @PostMapping("/updateAssignFreight")
    public CommonResult updateAssignFreight(@RequestBody YxAssignFreight yxAssignFreight) {
        return CommonResult.success(freightTemplateService.updateAssignFreight(yxAssignFreight));
    }

    /**
     * 修改限制下单区域
     * @param yxAstrictRegion
     * @return
     */
    @PostMapping("/updateAstrictRegion")
    public CommonResult updateAstrictRegion(@RequestBody YxAstrictRegion yxAstrictRegion) {
        return CommonResult.success(freightTemplateService.updateAstrictRegion(yxAstrictRegion));
    }

    /**
     * 修改运费模板
     * @param yxFreightTemplate
     * @return
     */
    @PostMapping("/updateFreightTemplate")
    public CommonResult updateFreightTemplate(@RequestBody YxFreightTemplate yxFreightTemplate) {
        return CommonResult.success(freightTemplateService.updateFreightTemplate(yxFreightTemplate));
    }

    /**
     * 修改运费默认
     * @param id
     * @return
     */
    @GetMapping("/updateDefaults")
    public CommonResult updateDefaults(@RequestParam(value = "id" ,defaultValue = "0")Integer id,@RequestParam(value = "platformData") String platformData) {
        return CommonResult.success(freightTemplateService.updateDefaults(id,platformData));
    }

    /**
     * 模板详情
     * @return
     */
    @GetMapping("/selectYxFreightTemplate")
    public CommonResult<FreightTemplateResponse> selectFreightTemplateResponse(Integer id) {
        return CommonResult.success(freightTemplateService.selectFreightTemplateResponse(id));
    }

    /**
     * 根据商品id查询运费模板
     */
    @GetMapping("/selectYxFreightTemplateByProductId")
    public CommonResult<FreightTemplateResponse> selectYxFreightTemplateByProductId(Integer productId) {
        return CommonResult.success(freightTemplateService.selectYxFreightTemplateByProductId(productId));
    }

    /**
     * 根据商品id查询供应链运费模板
     */
    @GetMapping("/selectChainFreightTemplateByProductId")
    public CommonResult<FreightTemplateResponse> selectChainFreightTemplateByProductId(Integer productId) {
        return CommonResult.success(freightTemplateService.selectChainFreightTemplateByProductId(productId));
    }


    /**
     * 查询默认商品模板
     */
    @GetMapping("/selectDefaultFreightTemplate")
    public CommonResult<FreightTemplateResponse> selectDefaultFreightTemplate(@RequestParam(value = "platformData") String platformData) {
        return CommonResult.success(freightTemplateService.selectDefaultFreightTemplate(platformData));
    }

    /**
     * 同步商品模板数据
     */
    @GetMapping("/syncYxFreightTemplate")
    public CommonResult syncYxFreightTemplate() {
        freightTemplateService.syncYxFreightTemplate();
        return CommonResult.success("同步完成");
    }

    @GetMapping("/syncYxAstricRegion")
    public CommonResult syncYxAstricRegion() {
        freightTemplateService.syncYxAstricRegion();
        return CommonResult.success("同步完成");
    }
}
